package com.qulei.demo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import com.qulei.demo.R;
import com.qulei.demo.dao.DaoFactory;
import com.qulei.demo.dao.PersonDao;
import com.qulei.demo.model.Person;

public class DBDemoActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		DaoFactory.getInstance(this).initialize();

		Button btn = (Button) findViewById(R.id.btnInsert);
		btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				PersonDao dao = (PersonDao) DaoFactory.getInstance(
						DBDemoActivity.this.getApplicationContext())
						.createHuman(PersonDao.class);
				Person p = new Person();
				p.name = "qulei";
				p.sex = 0;
				dao.addPerson(p);
			}
		});

	}

	@Override
	protected void onDestroy() {
		// DaoFactory.getInstance(this).release();
		super.onDestroy();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			this.finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}